package com.liao.seckill.rabbitmq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author lzp
 * @version 1.0
 * lzpnb!
 */
@Service
@Slf4j
public class MQReceiver {

    @Resource
    private RabbitTemplate rabbitTemplate;

    @RabbitListener(queues = "queue")
    public void receive(Object msg) {
        log.info("接受到消息-->" + msg);

    }

    @RabbitListener(queues = "queue_fanout01")
    public void receive1(Object msg) {
        log.info("从queue_fanout01 接受到消息-->" + msg);
    }

    @RabbitListener(queues = "queue_fanout02")
    public void receive2(Object msg) {
        log.info("从queue_fanout02 接受到消息-->" + msg);
    }


    @RabbitListener(queues = "queue_direct01")
    public void queue_direct01(Object msg) {
        log.info("从queue_direct01 接受到消息-->" + msg);
    }

    @RabbitListener(queues = "queue_direct02")
    public void queue_direct02(Object msg) {
        log.info("从queue_direct02 接受到消息-->" + msg);
    }

    @RabbitListener(queues = "queue_topic01")
    public void queue_topic01(Object msg) {
        log.info("从queue_topic01 接受到消息-->" + msg);
    }

    @RabbitListener(queues = "queue_topic02")
    public void queue_topic02(Object msg) {
        log.info("从queue_topic02 接受到消息-->" + msg);
    }


    @RabbitListener(queues = "queue_header01")
    public void queue_header01(Message message) {
        log.info("从queue_header01 接受到消息对象-->" + message);
        log.info("从queue_header01 接受到消息内容-->" + new String(message.getBody()));
    }

    @RabbitListener(queues = "queue_header02")
    public void queue_header02(Message message) {
        log.info("从queue_header02 接受到消息对象-->" + message);
        log.info("从queue_header02 接受到消息内容-->" + new String(message.getBody()));
    }
}
